package org.seckill.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.seckill.model.SuccessKilled;
import org.seckill.model.SuccessKilledCriteria;

public interface SuccessKilledMapper {
    @SelectProvider(type=SuccessKilledSqlProvider.class, method="countByExample")
    long countByExample(SuccessKilledCriteria example);

    @DeleteProvider(type=SuccessKilledSqlProvider.class, method="deleteByExample")
    int deleteByExample(SuccessKilledCriteria example);

    @Delete({
        "delete from success_killed",
        "where seckill_id = #{seckillId,jdbcType=BIGINT}",
          "and user_phone = #{userPhone,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(@Param("seckillId") Long seckillId, @Param("userPhone") Long userPhone);

    @Insert({
        "insert into success_killed (seckill_id, user_phone, ",
        "state, create_time)",
        "values (#{seckillId,jdbcType=BIGINT}, #{userPhone,jdbcType=BIGINT}, ",
        "#{state,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(SuccessKilled record);

    @InsertProvider(type=SuccessKilledSqlProvider.class, method="insertSelective")
    int insertSelective(SuccessKilled record);

    @SelectProvider(type=SuccessKilledSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="seckill_id", property="seckillId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="user_phone", property="userPhone", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<SuccessKilled> selectByExample(SuccessKilledCriteria example);

    @Select({
        "select",
        "seckill_id, user_phone, state, create_time",
        "from success_killed",
        "where seckill_id = #{seckillId,jdbcType=BIGINT}",
          "and user_phone = #{userPhone,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="seckill_id", property="seckillId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="user_phone", property="userPhone", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    SuccessKilled selectByPrimaryKey(@Param("seckillId") Long seckillId, @Param("userPhone") Long userPhone);

    @UpdateProvider(type=SuccessKilledSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") SuccessKilled record, @Param("example") SuccessKilledCriteria example);

    @UpdateProvider(type=SuccessKilledSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") SuccessKilled record, @Param("example") SuccessKilledCriteria example);

    @UpdateProvider(type=SuccessKilledSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SuccessKilled record);

    @Update({
        "update success_killed",
        "set state = #{state,jdbcType=TINYINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where seckill_id = #{seckillId,jdbcType=BIGINT}",
          "and user_phone = #{userPhone,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(SuccessKilled record);
}